package main;


import sort.ArraySort;

import java.lang.reflect.Array;
import java.util.*;

/**
 * 主函数，测试类
 *
 * @author HuWLin
 * */
public class Test {
    public static void main(String[] args) {
        testSort();
    }


    /*
    * 各种排序测试对比
    * */
    public static void testSort(){
        final int testLen = 50000;
        ArraySort sort = new ArraySort();
        Random r = new Random();
        int[] bubble = new int[testLen];
        int[] select = new int[testLen];
        int[] insert = new int[testLen];
        int[] shell = new int[testLen];
        int[] merge = new int[testLen];
        int[] quick = new int[testLen];
        int[] count = new int[testLen];
        int[] radix = new int[testLen];
        int[] heap = new int[testLen];
        int[] java = new int[testLen];
        ArrayList<Integer> bucket = new ArrayList<>();
        for(int i = 0;i < testLen;i ++){
            int n = r.nextInt(2000000);
            bubble[i] = n;
            select[i] = n;
            insert[i] = n;
            shell[i] = n;
            merge[i] = n;
            quick[i] = n;
            count[i] = n;
            bucket.add(n);
            radix[i] = n;
            heap[i] = n;
            java[i] = n;
        }

        //Arrays排序
        long start = System.currentTimeMillis();
        Arrays.sort(java);
        long end = System.currentTimeMillis();
        System.out.println("Arrays排序用时：" + (end - start) + "ms");

        //冒泡排序
        start = System.currentTimeMillis();
        sort.bubbleSort(bubble);
        end = System.currentTimeMillis();
        System.out.println("冒泡排序用时：" + (end - start) + "ms");

        //选择排序
        start = System.currentTimeMillis();
        sort.selectSort(select);
        end = System.currentTimeMillis();
        System.out.println("选择排序用时：" + (end - start) + "ms");

        //插入排序
        start = System.currentTimeMillis();
        sort.insertSort(insert);
        end = System.currentTimeMillis();
        System.out.println("插入排序用时：" + (end - start) + "ms");

        //希尔排序
        start = System.currentTimeMillis();
        sort.shellSort(shell);
        end = System.currentTimeMillis();
        System.out.println("希尔排序用时：" + (end - start) + "ms");

        //归并排序
        start = System.currentTimeMillis();
        int[] mergeRes = sort.mergeSort(merge);
        end = System.currentTimeMillis();
        System.out.println("归并排序用时：" + (end - start) + "ms");

        //快速排序
        start = System.currentTimeMillis();
        sort.quickSort(quick);
        end = System.currentTimeMillis();
        System.out.println("快速排序用时：" + (end - start) + "ms");

        //计数排序
        start = System.currentTimeMillis();
        sort.countSort(count);
        end = System.currentTimeMillis();
        System.out.println("计数排序用时：" + (end - start) + "ms");

        //计数排序
        start = System.currentTimeMillis();
        ArrayList<Integer> bucketRes = sort.bucketSort(bucket);
        end = System.currentTimeMillis();
        System.out.println("桶排序用时：" + (end - start) + "ms");

        //基数排序
        start = System.currentTimeMillis();
        sort.radixSort(radix);
        end = System.currentTimeMillis();
        System.out.println("基数序用时：" + (end - start) + "ms");

        //堆排序
        start = System.currentTimeMillis();
        sort.heapSort(heap);
        end = System.currentTimeMillis();
        System.out.println("堆序用时：" + (end - start) + "ms");


        System.out.println("数据校对:\n前五位：\n冒泡排序\t选择排序\t插入排序\t希尔排序\t归并排序\t快速排序\t计数排序\t桶排序\t基数排序\t堆排序");
        for(int i = 0;i < 5;i ++){
            System.out.format("%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n",
                    bubble[i],select[i],insert[i],shell[i],mergeRes[i],quick[i],count[i],bucketRes.get(i),radix[i],heap[i]);
        }

        System.out.println("后五位：\n冒泡排序\t选择排序\t插入排序\t希尔排序\t归并排序\t快速排序\t计数排序\t桶排序\t基数排序\t堆排序");
        for(int i = testLen - 6;i < testLen;i ++){
            System.out.format("%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n",
                    bubble[i],select[i],insert[i],shell[i],mergeRes[i],quick[i],count[i],bucketRes.get(i),radix[i],heap[i]);
        }
    }

}
